//
//  ETKeyboardHandler.swift
//  XingCeHelper
//
//  Created by 申铭 on 2023/2/8.
//

import Foundation
import ETKeyboard

let kScreenWidth = UIScreen.main.bounds.width
let kScreenHeight = UIScreen.main.bounds.height

class ETKeyboardHandler: NSObject {
    
    /// 单azacvbazacvb
    static let shared = ETKeyboardHandler.init()
    private override init() {}
    
    func setup() {
        ETKeyboardThemeManager.shared().delegate = self
    }
}

extension ETKeyboardHandler: ETKeyboardThemeDelegate {
    func setKeyboardHeight() -> CGFloat {
        if kScreenHeight < 700 {
            return 300
        } else if kScreenHeight < 800 {
            return 350
        }
        return 400
    }
    
    func setKeyboardTheme(_ type: ETKeyboardType) -> ETKeyboardTheme? {
        switch type {
        case .customNumber1:
            let theme = ETKeyboardTheme()
            if kScreenHeight < 700 {
                theme.keyboardEdgeInsets = UIEdgeInsets(top: 10, left: 20, bottom: 20, right: 20)
            } else {
                theme.keyboardEdgeInsets = UIEdgeInsets(top: 10, left: 40, bottom: 50, right: 40)
            }
            theme.keyboardBtnVerticalMargin = 2;
            theme.keyboardBtnHorizontalMargin = 2;
            theme.letterKeyboardFunctionBtnHorizontalMargin = 0;
            theme.backgroundColor = UIColor(named: "keyboard_bg")
            return theme
        default: break;
        }
        
        return nil;
    }
    
    func setKeyboardBtnTheme(_ type: ETKeyboardButtonType) -> ETKeyboardBtnTheme? {
        let theme = ETKeyboardBtnTheme()
        theme.normalColor = UIColor(named: "keyboard_btn_bg")
        theme.titleColor = .label
        theme.cornerRadius = 5.0
        theme.fontSize = 18.0
        
        switch type {
        case .decimal:
            theme.title = "."
            return theme
        case .done:
            theme.title = "确认"
            theme.fontSize = 12
            return theme
        case .clear:
            theme.title = "清除"
            theme.fontSize = 12
            return theme
        case .delete:
            theme.title = "删除"
            theme.fontSize = 12
            return theme
        default: return theme;
        }
    }
}
